<?php
/**
 * @author Wamania, RenardBlanc
 * Dernière modification : $Date: 2010-08-01 14:38:55 +0000 (Sun, 01 Aug 2010) $
 * Par Qui ?: $Author: dovecyber@gmail.com $
 * Révision : $Rev: 39 $
 *
 **/
define ('AEDITUUS_ROOT', '../');
require_once AEDITUUS_ROOT.'commun.php';

// L'objet user, démarrage de la session utilisateur
$user = new AeUser();
$user->session_begin();
$userData = $user->getUserData();

$db = db::getInstance();

$transaction_id = $user->transaction_id;
$transaction = $db->get_row("SELECT * FROM ".$cfg['prefix']."transaction WHERE id_trans=?", array($transaction_id));

// On récupère les donnée de la commande en demande
$data = array(
    'pseudo' => (isset($user->pseudo) ? $user->pseudo : ''),
    'email' => (isset($user->email) ? $user->email : ''),
    'AEDITUUS_ROOT' => AEDITUUS_ROOT,
    'user' => $user,
    'transaction' => $transaction
);

$result = $db->get_array( "SELECT name, value FROM ".$cfg['prefix']."config" );
foreach ($result as $config)
{
    $data[$config->name] = $config->value;
}

// gestion des données à afficher
$data['id'] = $user->id;
$data['pseudo'] = $userData['pseudo'];
$data['courriel'] = $userData["email"];

//$ip = ($userData['ip']);

$data['order_id'] = $transaction->id_trans;
$data['malert'] = $transaction->compte_de;
$data['devise_de'] = $transaction->devise_de;
$data['mliberty'] = $transaction->compte_vers;
$data['devise_vers'] = $transaction->devise_vers;
$data['mont1'] = $transaction->mont1;
$data['mont1_bis'] = $transaction->mont1_bis;
$data['mont2'] = $transaction->mont2;
$data['mont2_bis'] = $transaction->mont2_bis;

// extraction nom
$pseudo_extract = substr($userData['pseudo'], 0,3);

// extraction ID client
$gds_extract = substr($userData['gds'], 0,3);

// nbre aléatoire
$aleat= rand(100000, 999999);

// concatenation du login
$login = $pseudo_extract . $gds_extract . $aleat;
// création du code d'affiliation
$codepart1 = $pseudo_extract . $gds_extract;

$codepart1maj=strtoupper($codepart1);
$data['refcmde'] = "APLRUU".$transaction->mont2 . $codepart1maj . $aleat;

$db->query("UPDATE ".$cfg['prefix']."transaction SET ref_preco=?, status_trans='precommande' WHERE id_trans=?", array($data['refcmde'], $transaction->id_trans));
$db->query("UPDATE ".$cfg['prefix']."gainservices SET status_trans='precommande' WHERE id_trans=?", array($transaction->id_trans));

echo render_view ($data, AEDITUUS_ROOT.'ap/template/default/com_aplrUU.tpl.php', AEDITUUS_ROOT.'ap/template/default/index.tpl.php');
